<?php
  	@include '../conn/conn.php';
//	@include '../islogin.php';
    if(!empty($_POST)){
		$username = $_POST['username'];
		$password = $_POST['password'];
		$password2 = $_POST['password2'];
		if (empty($username)){
            echo '{"status":false,"data":"没有填写用户名，请重新输入！"}';
            exit();
        }
        if (empty($password)){
            echo '{"status":false,"data":"没有填写密码，请重新输入！"}';
            exit();
        }
        if (empty($password2)){
            echo '{"status":false,"data":"没有填写确认密码，请重新输入！"}';
            exit();
        }
		$sql = "select * from tb_userlist where username='$username'";
		$result = mysqli_query($link,$sql);
		$nums = mysqli_num_rows($result);
		if($nums > 0){
            echo '{"status":false,"data":"已有相同的用户名，请重新输入！"}';
            exit();
		}else{
			if ($password == $password2) {
				$sql2 ="insert into tb_userlist (username,passwd,permission) values ('$username','".md5($password)."','1')";
				$result = mysqli_query($link,$sql2);
				if ($result) {
                    echo '{"status":true,"data":"添加用户成功！"}';
                    exit();
				}else{
                    echo '{"status":false,"data":"添加用户失败！"}';
                    exit();
                }
			}else{
                echo '{"status":false,"data":"两次密码不一致，请重新输入"}';
			}
		}
	}

 ?>